/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tabelamodelcolumnmodel.orcamento;

import eloma.classe.orcamento.Orcamento;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author icaro.klinger
 */
public class OrcamentoTableModel extends AbstractTableModel {

    private List<Orcamento> listOrcamento;
    private boolean ordenarPorNome = true;

    public OrcamentoTableModel(List<Orcamento> listOrcamento) {
        this.listOrcamento = listOrcamento;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Orcamento orc = listOrcamento.get(rowIndex);
        NumberFormat nf = NumberFormat.getCurrencyInstance();
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
        switch (columnIndex) {
            case 0:
                return orc.getCliente().getNome();
            case 1:
                return dateFormat.format(orc.getData());
            case 2:
                return nf.format(orc.getPagamento().getValorTotal());
            case 3:
                return null;
        }

        return null;
    }

    @Override
    public int getRowCount() {
        return listOrcamento.size();
    }

    @Override
    public int getColumnCount() {
        return 3;
    }

    public Orcamento getValoresOrcamento(int rowIndex) {
        return listOrcamento.get(rowIndex);
    }

    public boolean isOrdenarPorNome() {
        return ordenarPorNome;
    }

    public void setOrdenarPorNome(boolean ordenarPorNome) {
        this.ordenarPorNome = ordenarPorNome;
    }

}
